package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.queryparam.NursingProjectQueryParam;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理有关接口")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询
     *
     * @param npqp
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> getPage(NursingProjectQueryParam npqp) {

        PageResponse<NursingProjectVo> result = nursingProjectService.getPage(npqp);

        return ResponseResult.success(result);
    }

    /**
     * 新增护理项目
     *
     * @param npd
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto npd) {
        nursingProjectService.addNursingProject(npd);//完成数据保存

        return ResponseResult.success();
    }

    /**
     * 回显
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult getByIdNursingProject(@PathVariable Long id) {

        NursingProjectVo nursingProjectVo = nursingProjectService.getByIdNursingProject(id);

        return ResponseResult.success(nursingProjectVo);
    }

    /**
     * 修改护理项目
     *
     * @param npd
     * @return
     */
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto npd) {

        nursingProjectService.updateNursingProject(npd);

        return ResponseResult.success();
    }

    /**
     * 启用禁用
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理项目")
    public ResponseResult statusNursingProject(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理项目的id : {}", id);
        log.info("启用禁用护理项目的status : {}", status);

        nursingProjectService.statusNursingProject(id, status);

        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNursingProject(@PathVariable Long id) {
        nursingProjectService.deleteNursingProject(id);

        return ResponseResult.success();
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult allList() {
        List<NursingProjectVo> allList = nursingProjectService.allList();

        return ResponseResult.success(allList);
    }
}
